package cn.rokhdelar.ams.management.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.rokhdelar.ams.management.domain.po.SysAuthorityCategory;
import cn.rokhdelar.ams.management.domain.vo.AuthorityCategoryVO;
import cn.rokhdelar.ams.management.domain.vo.AuthorityVO;
import cn.rokhdelar.ams.management.mapper.SysAuthorityCategoryMapper;
import cn.rokhdelar.ams.management.service.SysAuthorityCategoryService;
import cn.rokhdelar.ams.management.service.SysAuthorityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
    * 
    * @author Rokhdelar
    * @since 2025/3/26 -- 15:34
**/
@Service
@RequiredArgsConstructor
public class SysAuthorityCategoryServiceImpl extends ServiceImpl<SysAuthorityCategoryMapper, SysAuthorityCategory>
        implements SysAuthorityCategoryService {
    final SysAuthorityService sysAuthorityService;
    /**
     * 获取权限分类树形数据
     * @return 权限分类树形数据
     */
    @Override
    public List<AuthorityCategoryVO> getTree() {
        List<AuthorityCategoryVO> authorityCategoryVoList = BeanUtil.copyToList(list(), AuthorityCategoryVO.class);
        List<AuthorityVO> authorityVOList = BeanUtil.copyToList(sysAuthorityService.list(), AuthorityVO.class);
        for (AuthorityCategoryVO authorityCategoryVO : authorityCategoryVoList) {
            for (AuthorityVO authorityVO : authorityVOList) {
                if (authorityVO.getCategory().equals(authorityCategoryVO.getId())) {
                    authorityCategoryVO.getAuthorityList().add(authorityVO);
                }
            }
        }
        return authorityCategoryVoList;
    }
}
